<?php

defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
if($_RQ['op']=='list'){
	$_SESSION['exid']=$id=intval($_RQ['id']);
	$_SESSION['extype']=$_SESSION['extype']=$type=intval($_RQ['type']);
	$params['uniacid']=$_SESSION['uniacid'];
	$params['groupid']=$id;
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','endtime','key','goodsstatus','balancestatus','scorestatus','couponstatus');
	$list=pdo_getslice('jy_exchange_code',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$v){
				$v['url']=custom_url('/index//code='.$v['key'],true);
				if($type==1){
					$v['status']=$v['goodsstatus'];
				}
				elseif($type==2){
					$v['status']=$v['balancestatus'];
				}
				elseif($type==3){
					$v['status']=$v['scorestatus'];
				}elseif($type==4){
					$v['status']=$v['couponstatus'];
				}
				$v['endtime']=date('Y-m-d H:i:s',$v['endtime']);
			}
		}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	exi($return);
}
